package com.meichis.mcsappframework.adapter.pagertabstrip;

import android.view.View;
import android.view.ViewGroup;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class PagerTabAdapter extends PagerAdapter {

    private String[] titleContainer;
    private View[] viewContainter;

    public PagerTabAdapter(String[] titleContainer, View[] viewContainter) {
        this.titleContainer = titleContainer;
        this.viewContainter = viewContainter;
    }

    //viewpager中的组件数量
    @Override
    public int getCount() {
        return viewContainter != null ? viewContainter.length : 0;
    }

    //滑动切换的时候销毁当前的组件
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView(viewContainter[position]);
    }

    //每次滑动的时候生成的组件
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ((ViewPager) container).addView(viewContainter[position]);
        return viewContainter[position];
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        return arg0 == arg1;
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleContainer[position];
    }

}
